Main site

Built-in Modules > Dropsite Class

Dropsite Class

Important: This plugin relies on third-party resources. The resources might change or be discontinued without notice. Ensure you test the plugin extensively before production use, implement error handling with a try-catch block, have a backup shipping rate ready, and reach out to our support with detailed descriptions of any unexpected issues.

Overview

The Dropsite class provides a way to fetch real-time shipping rates for "Dropsite" products.

Class Definition

class Dropsite {
  constructor(destination) {
    // Class constructor
  }

  async getRates(dropsiteProducts) {
    // Method to fetch rates
  }
}

Arguments

  • destination (Object): This corresponds to the "destination" field from the DATA JSON object provided to the calculateShippingRates function.

Usage Example

const dropsite = new Dropsite(DATA.destination);
const dropsiteProducts = [
  { dropsite_product_sku: "tml-ljj-v1200", quantity: 1 },
  { dropsite_product_sku: "dmb-td1-ad3-2", quantity: 1 },
  // ... additional products
];
const rates = await dropsite.getRates(dropsiteProducts);

This example illustrates how to create an instance of the Dropsite class using the destination information from your shipping rate calculation data. The getRates method is then called to retrieve shipping rates for a list of Dropsite products, each specified by a dropsite_product_sku and its quantity. The structure of the returned rates aligns with the format of Shopify's shipping rates.

Sample AI Prompt

I'd like a shipping rate calculator for items from Dropsite.
Use the items sku as the Dropsite product sku.

Sample AI Output

import { enrichItemDetails } from "./modules.js";
import { Dropsite } from "./modules.js";

export async function calculateShippingRates(DATA, env) {
  try {
    // Enrich items with additional details
    DATA = await enrichItemDetails(DATA);

    // Extract destination info
    const destination = DATA.destination;

    // Create a Dropsite instance with the destination info
    const dropsite = new Dropsite(destination);

    // Get the Dropsite products from the items
    const dropsiteProducts = DATA.items.map((item) => ({
      dropsite_product_sku: item.sku,
      quantity: item.quantity,
    }));

    // Get the shipping rates from Dropsite
    const rates = await dropsite.getRates(dropsiteProducts);

    return { rates };
  } catch (error) {
    // Return an error rate
    return {
      rates: [
        {
          service_name: "",
          service_code: "",
          total_price: null,
          description: "",
          currency: "",
          min_delivery_date: "",
          max_delivery_date: "",
        },
      ],
    };
  }
}